package com.project.service.saleManagerService.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.SaleOrderBean;
import com.project.bean.ShopCarBean;
import com.project.mapper.saleManagerMapper.ISaleOrderMapper;
import com.project.service.saleManagerService.ISaleOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.Collection;

/**
 * 销售订单实现类
 */
@Service
@Transactional
public class SaleOrderServiceImpl implements ISaleOrderService {
    @Autowired
    private ISaleOrderMapper mapper;

    @Override
    public void addSaleOrder(SaleOrderBean salesOrder, Collection<ShopCarBean> shopList) {
        mapper.addOrder(salesOrder);
        mapper.addOrderInfo(salesOrder.getId(),shopList);
    }

    @Override
    public SaleOrderBean findById(int saleOrderId) {
        return mapper.findById(saleOrderId);
    }

    @Override
    public PageInfo<SaleOrderBean> findByItem(int pageNO, String customerName, LocalDate startDate, LocalDate endDate) {
        PageHelper.startPage(pageNO,PAGESIZE);
        PageInfo<SaleOrderBean> pageInfo = PageInfo.of(mapper.findByItem(customerName,startDate,endDate));
        return pageInfo;
    }
}
